﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using CommonManage = DevelopStudio.Common.Manage;
using SNSHelper.Common;

namespace DevelopStudio.Common.Basic
{
    [Serializable]
    [XmlRoot("Root")]
    public class DSFileDiffUnitInfo
    {
        [XmlElement("Status")]
        public int Status;

        [XmlElement("DisplayPath")]
        public string DisplayPath { get; set; }

        [XmlElement("WorkingCopyPath")]
        public string WorkingCopyPath { get; set; }

        [XmlElement("Left")]
        public DSFileInfo Left;

        [XmlElement("Right")]
        public DSFileInfo Right;

        public bool UnPack(string path)
        {
            if (Path.GetExtension(path) != AppConst.DiffToolFileSuffix)
            {
                return false;
            }

            Dictionary<string, string> unZipFiles = new Dictionary<string, string>();

            Left.Path = CommonManage.Utility.GetDiffTempFullFileName(DisplayPath.Replace(WorkingCopyPath, ""), Left.Revision);
            unZipFiles.Add(Left.Key, Left.Path);


            Right.Path = CommonManage.Utility.GetDiffTempFullFileName(DisplayPath.Replace(WorkingCopyPath, ""), Right.Revision);
            unZipFiles.Add(Right.Key, Right.Path);

            UnZip.UnZipFiles(unZipFiles, path);
            return true;
        }
    }
}
